package com.peanut.baby.http;

/**
 * Created by anonymouslystudio on 2017/7/21.
 */

public class ApiException extends RuntimeException{
    public static final String ERROR_NETWORK_FAILED = "-1000";
    public static final String ERROR_TOKEN_EXPRIED  = "-30";
    public static final String ERROR_NEED_TOKEN     = "-20";
    public static final String ERROR_LACK_OF_POINT  = "-50";
    public static final String ERROR_BIND_CONFLIC   = "-8";
    public static final String ERROR_BIND_WEXIN_CONFLIC  = "-31";

    public String mErrorCode;

    public ApiException(String errorCode, String errorMessage) {
        super(errorMessage);
        mErrorCode = errorCode;
    }

    /**
     * 判断是否是token失效
     *
     * @return 失效返回true, 否则返回false;
     */
    public boolean isTokenExpried() {
        return mErrorCode.equals(ERROR_TOKEN_EXPRIED);
    }
    public boolean isLackOfPoint() {
        return mErrorCode.equals(ERROR_LACK_OF_POINT);
    }
    public boolean isNeedToken() {
        return mErrorCode.equals(ERROR_NEED_TOKEN);
    }
    public boolean isBindConflic() {
        return mErrorCode.equals(ERROR_BIND_CONFLIC);
    }

    public static boolean isApiException(String code){
        return (code.equals(ERROR_TOKEN_EXPRIED)
                || code.equals(ERROR_NEED_TOKEN)
                || code.equals(ERROR_LACK_OF_POINT));
    }
}
